package com.chd.driversystem.domain;

import android.os.Parcel;
import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Transient;

import java.io.Serializable;
import java.util.Date;

import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Unique;

/**
 * Created by shawnfly on 17-5-2.
 */
@Entity(indexes = {@Index(value = "id ASC",unique = true)})
public class User implements Parcelable {
    @Id(autoincrement = true)
    private Long id;
    private String name;
    @Unique
    private String code;
    private String password;
    @NotNull
    private Boolean isManager;
    private Long managerId;
    private String phoneArea;
    private String phoneNum;
    private String email;
    private String avator;
    private Boolean assigned;
    private Date loginDate;
    private Long teamId;

    protected User(Parcel in) {
        id = in.readLong();
        if (id < 0) {
            id = null;
        }
        name = in.readString();
        code = in.readString();
        password = in.readString();
        isManager = in.readLong() != 0;
        managerId = in.readLong();
        phoneArea = in.readString();
        phoneNum = in.readString();
        email = in.readString();
        avator = in.readString();
        assigned = in.readLong() != 0;
        loginDate = new Date(in.readLong());
        teamId = in.readLong();
    }

    @Generated(hash = 802130798)
    public User(Long id, String name, String code, String password,
            @NotNull Boolean isManager, Long managerId, String phoneArea,
            String phoneNum, String email, String avator, Boolean assigned,
            Date loginDate, Long teamId) {
        this.id = id;
        this.name = name;
        this.code = code;
        this.password = password;
        this.isManager = isManager;
        this.managerId = managerId;
        this.phoneArea = phoneArea;
        this.phoneNum = phoneNum;
        this.email = email;
        this.avator = avator;
        this.assigned = assigned;
        this.loginDate = loginDate;
        this.teamId = teamId;
    }

    @Generated(hash = 586692638)
    public User() {
    }

    public static final Creator<User> CREATOR = new Creator<User>() {
        @Override
        public User createFromParcel(Parcel in) {
            return new User(in);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (id != null) {
            dest.writeLong(id);
        } else {
            dest.writeLong(-1);
        }
        dest.writeString(name);
        dest.writeString(code);
        dest.writeString(password);
        dest.writeLong((long) (isManager ? 1 : 0));
        dest.writeLong(managerId);
        dest.writeString(phoneArea);
        dest.writeString(phoneNum);
        dest.writeString(email);
        dest.writeString(avator);
        dest.writeLong((long) (assigned ? 1 : 0));
        dest.writeLong(loginDate.getTime());
        dest.writeLong(teamId);
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Boolean getIsManager() {
        return this.isManager;
    }

    public void setIsManager(Boolean isManager) {
        this.isManager = isManager;
    }

    public Long getManagerId() {
        return this.managerId;
    }

    public void setManagerId(Long managerId) {
        this.managerId = managerId;
    }

    public String getPhoneArea() {
        return this.phoneArea;
    }

    public void setPhoneArea(String phoneArea) {
        this.phoneArea = phoneArea;
    }

    public String getPhoneNum() {
        return this.phoneNum;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAvator() {
        return this.avator;
    }

    public void setAvator(String avator) {
        this.avator = avator;
    }

    public Boolean getAssigned() {
        return this.assigned;
    }

    public void setAssigned(Boolean assigned) {
        this.assigned = assigned;
    }

    public Date getLoginDate() {
        return this.loginDate;
    }

    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }

    public Long getTeamId() {
        return this.teamId;
    }

    public void setTeamId(Long teamId) {
        this.teamId = teamId;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", code='" + code + '\'' +
                ", password='" + password + '\'' +
                ", isManager=" + isManager +
                ", managerId=" + managerId +
                ", phoneArea='" + phoneArea + '\'' +
                ", phoneNum='" + phoneNum + '\'' +
                ", email='" + email + '\'' +
                ", avator='" + avator + '\'' +
                ", assigned=" + assigned +
                ", loginDate=" + loginDate +
                ", teamId=" + teamId +
                '}';
    }
}
